package com.study.provider.service.impl;

import com.alibaba.fastjson.JSON;
import com.study.provider.dto.UserInfoDto;
import com.study.provider.service.UserInfoManage;
import com.study.provider.util.RedisUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @author anner
 * @description: TODO
 * @date 2021/4/18 21:53
 */
@Service
@Slf4j
public class UserInfoManageImpl implements UserInfoManage {

    @Autowired
    private RedisUtil redisUtil;

    /**
     * 缓存用户信息
     * @return
     */
    public Object saveUserValue() {
        // 固定size
        List<String> parents = Arrays.asList("小李", "秋菊");

        // 不固定size
        List<String> hobbies = new ArrayList<String>(Arrays.asList("看剧","散步","闲聊"));
        hobbies.add("coding?");
        UserInfoDto userInfoDto = UserInfoDto.builder()
                .userName("llyuanyuan").telephone("13026180539").companyId("0513563")
                .parents(parents).hobbies(hobbies)
                .build();
        Object toJSON = JSON.toJSON(userInfoDto);
        boolean exit = redisUtil.set("liyy", toJSON);
        log.info("存储 key:{}, value:{}, 成功:{}", "liyy", redisUtil.get("liyy"), exit);
        return userInfoDto;
    }
}
